package net.wanho.hospital.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@EnableKnife4j // 启用Knife4j
public class Knife4jConfig {

    /**
     * 创建Restful API文档内容
     */
    @Bean
    public Docket Api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                // 指定要暴露的接口所在包
                .apis(RequestHandlerSelectors.basePackage("net.wanho.hospital.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * API的基本信息
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("医院管理系统后端API接口文档")
                .description("欢迎访问后端API接口文档")
                .contact(new Contact("tangxiaoyang","https://github.com/tangyang8942","tangxiaoyang@qq.com"))
                .version("1.0")
                .build();
    }

}